package com.justnow.offer;

import com.sun.xml.internal.ws.policy.EffectiveAlternativeSelector;

/**
 * @author justnow
 * Created on 2020-09-12
 * Description
 */
public class Solution39 {
    public boolean hasCycle(ListNode head) {
        if (head == null || head.next == null) {
            return false;
        }
        ListNode fast = head.next;
        ListNode slow = head;
        while (slow != fast) {
            if (fast == null || fast.next == null) {
                return false;
            }
            fast = fast.next.next;
            slow = slow.next;
        }
        return true;
    }
}

class ListNode {
    int val;
    ListNode next;
    public ListNode(int val) {
        this.val = val;
    }
}
